/**
 * 
 */
package com.myBase.core.modules.order.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.myBase.core.entity.GoldcoinOrder;
import com.myBase.core.facade.service.GoldcoinOrderServiceFacade;
import com.myBase.framework.common.config.Global;
import com.myBase.common.persistence.Page;
import com.myBase.framework.common.utils.StringUtils;
import com.myBase.framework.common.web.BaseController;

/**
 * 金币订单Controller
 * @author gebao
 * @version 2017-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/order/goldcoinOrder")
public class GoldcoinOrderController extends BaseController {

    //@Autowired
    private GoldcoinOrderServiceFacade goldcoinOrderService;

    @ModelAttribute
    public GoldcoinOrder get(@RequestParam(required = false) String id) {
        GoldcoinOrder entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = goldcoinOrderService.get(id);
        }
        if (entity == null) {
            entity = new GoldcoinOrder();
        }
        return entity;
    }

    @RequiresPermissions("order:goldcoinOrder:view")
    @RequestMapping(value = { "list", "" })
    public String list(GoldcoinOrder goldcoinOrder, HttpServletRequest request, HttpServletResponse response,
            Model model) {
        Page<GoldcoinOrder> page = goldcoinOrderService.findPage(new Page<GoldcoinOrder>(request, response),
                goldcoinOrder);
        model.addAttribute("page", page);
        return "modules/order/goldcoinOrderList";
    }

    @RequiresPermissions("order:goldcoinOrder:view")
    @RequestMapping(value = "form")
    public String form(GoldcoinOrder goldcoinOrder, Model model) {
        model.addAttribute("goldcoinOrder", goldcoinOrder);
        return "modules/order/goldcoinOrderForm";
    }

    @RequiresPermissions("order:goldcoinOrder:edit")
    @RequestMapping(value = "save")
    public String save(GoldcoinOrder goldcoinOrder, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, goldcoinOrder)) {
            return form(goldcoinOrder, model);
        }
        goldcoinOrderService.save(goldcoinOrder);
        addMessage(redirectAttributes, "保存金币订单成功");
        return "redirect:" + Global.getAdminPath() + "/order/goldcoinOrder/?repage";
    }

    @RequiresPermissions("order:goldcoinOrder:edit")
    @RequestMapping(value = "delete")
    public String delete(GoldcoinOrder goldcoinOrder, RedirectAttributes redirectAttributes) {
        goldcoinOrderService.delete(goldcoinOrder);
        addMessage(redirectAttributes, "删除金币订单成功");
        return "redirect:" + Global.getAdminPath() + "/order/goldcoinOrder/?repage";
    }

}